package com.sixth.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sixth.dao.AclRoleDao;
import com.sixth.entity.AclPermission;
import com.sixth.entity.AclRole;
import com.sixth.entity.RoleVo;
import com.sixth.service.AclRoleService;
import com.sixth.until.CommonResult;
import com.sixth.until.OrderNoUtil;
import com.sixth.until.TableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @program: self-tui-education
 * @description:
 * @author: 高振杨
 * @create: 2022-04-25 17:18
 **/
@Service
public class AclRoleServiceImpl  implements AclRoleService {
    @Autowired
    private AclRoleDao aclRoleDao;

    @Override
    public TableResult findRoleByRoleName(Integer roleCurrentPage, Integer rolePageSize, AclRole role) {
        PageHelper.startPage(roleCurrentPage,rolePageSize);
        String roleName = role.getRoleName();
        List<AclRole> roleList=aclRoleDao.findRoleByRoleName(roleName);
        PageInfo<AclRole> pageInfo = new PageInfo<>(roleList);
        return new TableResult(2000,"查询成功",pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public CommonResult fenUserRole(RoleVo roleVo) {

        String id = roleVo.getUserId();
        String[] roleIds = roleVo.getRoleIds();
        aclRoleDao.deleteUserIdAndRoleId(id);
        Date date = new Date();

        //System.out.println("++++++++++++"+roleIds+"+++++++++++++++++++++++");
        for (String ids:roleIds) {
            String aurid = OrderNoUtil.getOrderNo();
            int row=aclRoleDao.insertRole(aurid,ids,id,date);
        }
            return new CommonResult(2000,"修改成功",null);
    }
}
